%==========================================================================
%=  This file is part of the Sound Restoration Project
%=  (c) Copyright Industrial Mathematics Institute
%=                University of South Carolina, Department of Mathematics
%=  ALL RIGHTS RESERVED
%=
%=  Author: Borislav Karaivanov
%==========================================================================

%==========================================================================
% List of the files on which this procedure depends:
%
% none
%
%==========================================================================

%==========================================================================
% The function "getSamplingRate" delivers in numeric representation the
% sampling rate specified in a given project structure.
% INPUT: "projectStruct" is a project structure specifying a certain
% sampling rate in terms of a strings appearing in a pop-up menu.
% OUTPUT: "samplingRate" returns the sampling rate specified in the project
% structure.
%==========================================================================
function samplingRate = getSamplingRate(projectStruct)

% Get the string currently selected in the pop-up menu.
stringToScan = projectStruct.samplingRate.choicesCellArr{projectStruct.samplingRate.currChoiceInd};

% Extract the first number from that string, if any number can be extracted
% at all.
scanArr = textscan(stringToScan, '%n');

% If a number is extracted, then multiply it by 1000. Otherwise, if the
% string is 'native' return the native sampling rate already stored in the
% project structure.
if (isempty(scanArr) == false)
    if (isempty(scanArr{1}) == false)
        samplingRate = scanArr{1}*1000;
    elseif ( (strcmpi(stringToScan, 'native') == true)&& ...
            (isfield(projectStruct.samplingRate, 'native') == true) )
        samplingRate = projectStruct.samplingRate.native;
    else
        samplingRate = [];
    end
else
    samplingRate = [];
end

return;
% end of the function "getSamplingRate"
